using System.Linq;
using Microsoft.Practices.Composite.Presentation.Commands;
using Microsoft.Practices.Unity;
using Shatkotha.Nokia;
using Shatkotha.WPF.Global.Data;
using Shatkotha.WPF.Global.Modules.SMS;
using Shatkotha.WPF.Global.Bases;
using Shatkotha.WPF.Global.Common.Controls.Dialog;
namespace Shatkotha.WPF.SMS.Presenters
{
    public class SmsPresenter:APresenter,ISmsPresenter
    {
        public SmsPresenter(ISmsView view,IUnityContainer container):base(view)
        {
            Container = container;
            NewSmsWizardCommand = new DelegateCommand<object>(ExecuteNewSmsWizardCommand);
        }

        public IUnityContainer Container { get; set; }

        public DelegateCommand<object> NewSmsWizardCommand { get; set; }

        private void ExecuteNewSmsWizardCommand(object obj)
        {
            var dialogPresenter = Container.Resolve<IDialogPresenter>();
            var dialogContent = Container.Resolve<INewSmsWizardPresenter>();
            if(dialogPresenter.ShowModal(dialogContent, "New SMS", DialogButton.OKCancel)== DialogResult.OK)
            {
                IPerson[] receipient = dialogContent.Recipients;
                string messageText = dialogContent.MessageText;
                NokiaPhoneHelper helper = new NokiaPhoneHelper();
                string [] numberArray = receipient.Select(p => p.Phone).ToArray();
                helper.SendSms(numberArray, messageText);
            }
        }
    }
}